package com.csdj.t309springboot.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;

//@Component
public class TestJob {

    private Logger log = LoggerFactory.getLogger("job");

    @Scheduled(cron = "0 8-11 * ? * 2-6")
    public void morningStart() {
        start();
    }

    @Scheduled(cron = "30 13-16 * ? * 2-6")
    public void afternoonStart(){
        start();
    }

    @Scheduled(cron = "50 8-11 * ? * 2-6")
    public void morningEnd() {
        end();
    }

    @Scheduled(cron = "20 14-17 * ? * 2-6")
    public void afternoonEnd(){
        end();
    }



    private void start(){
        log.info("播放上课铃声");
    }
    private void end(){
        log.info("播放下课铃声");
    }

    /**
     * cron="0 0,20,30,50 8-11,13-17 ? * 2-6"
     */
    private void play(){
        Calendar cal = Calendar.getInstance();
        int i = cal.get(Calendar.MINUTE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        switch (i){
            case 0:
                if(hour == 13)break;
                start();
                break;
            case 20:
                if(hour == 13)break;
                end();
                break;
            case 30:
                start();
                break;
            case 50:
                end();
        }
    }

}


